package com.cms.controllers.admin;

import com.cms.common.model.entity.AdminUser;
import com.cms.common.model.services.AdminUserService;
import com.cms.controllers.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/admin/logout")
public class LogoutController extends BaseController {
    @Autowired
    AdminUserService adminUserService;


    @GetMapping("")
    public String logout(HttpServletRequest request, HttpServletResponse response) {
        AdminUser adminUser = (AdminUser) request.getAttribute("adminUser");
        if (adminUser == null) {
            return "redirect:/admin/login";
        }
        adminUserService.logout(adminUser.getUuid(),request,response);


        return "redirect:/admin/login";
    }
}
